﻿function barReport(did){
    var p = new datasource();
    p.c = "Way.Bus.WMS.ST.Controllers.ChartReportController";
    var rdata = p.post("getCustProductNum", "startdate=2014-01-01&enddate=2015-12-31");
    //var rdata = [{ "customerid": "8", "customername": "瓦里安医疗设备（中国）有限公司", "innum": "274.00", "outnum": "174.00"}];

    var xdata = [];
    var ydata = [];
    var zdata = [];
    for (var dt in rdata) {
        xdata.push(rdata[dt].customername);
        ydata.push(parseFloat(rdata[dt].innum));
        zdata.push(parseFloat(rdata[dt].outnum));
    }
    drawBarChart(ydata, zdata, function (seriesData) {
        showChart(did, "客户业务量统计", xdata, null, seriesData, "bar", null, "件", "2014-01-01至今", null)
    })

}

function drawBarChart(ydata, zdata, callback) {
    var seriesData = [];
    ydata = { "name": "入库量(件)", "type": "bar", "data": ydata };
    zdata = { "name": "出库量(件)", "type": "bar", "data": zdata };
    seriesData.push(ydata);
    seriesData.push(zdata);
    if (callback) {
        callback(seriesData);
    }
}

function columnReport(did) {
    var p = new datasource();
    p.c = "Way.Bus.WMS.ST.Controllers.ChartReportController";
    var rdata = p.post("getWorkerKPI", "startdate1=2014-01-01&enddate1=2015-12-31");
    //var rdata = [{"workername":"张三","finishnum":"50","totalnum":"10"},{"workername":"李四","finishnum":"20","totalnum":"20"},{"workername":"王五","finishnum":"40","totalnum":"30"}];

    var xdata = [];
    var ydata = [];
    var zdata = [];
    for (var dt in rdata) {
        xdata.push(rdata[dt].workername);
        ydata.push(parseFloat(rdata[dt].finishnum));
        zdata.push(parseFloat(rdata[dt].totalnum));
    }
    drawColumnChart(ydata, zdata, function (seriesData) {
        showChart(did, "员工业绩考核-入库业务统计", xdata, null, seriesData, "column", null, "件", "2014-01-01至今", null)
    })

}

function drawColumnChart(ydata, zdata, callback) {
    var seriesData = [];
    ydata = { "name": "入库完成件数(件)", "type": "column", "data": ydata };
    zdata = { "name": "入库总件数(件)", "type": "column", "data": zdata };
    seriesData.push(ydata);
    seriesData.push(zdata);
    if (callback) {
        callback(seriesData);
    }
}